package cn.com.flower.admin.content.dao.persist.repository.impl;

import cn.com.flower.admin.content.dao.persist.mapper.CategoryMapper;
import cn.com.flower.admin.content.dao.persist.repository.ICategoryRepository;
import cn.com.flower.admin.content.pojo.entity.Category;
import cn.com.flower.admin.content.pojo.vo.CategoryStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Slf4j
@Repository
public class CategoryRepositoryImpl implements ICategoryRepository{


    @Autowired
    private CategoryMapper mapper;

    @Override
    public int insert(Category category) {
        log.debug("开始执行【新增类别】的数据访问，参数：{}"+category);
        return mapper.insert(category);
    }

    @Override
    public int countByName(String name) {
        log.debug("开始执行【统计匹配名称的类别的数量】的数据访问，参数：{}"+name);
        QueryWrapper<Category> wrapper = new QueryWrapper();
        wrapper.eq("name", name);
        Integer count = mapper.selectCount(wrapper);
        return count;
    }

    @Override
    public CategoryStandardVO getStandardById(Long id) {
        log.debug("开始执行【根据id查询类别详情】的数据访问，参数：{}"+id);
        return mapper.getStandardById(id);
    }

    @Override
    public int updateById(Long id) {
       log.debug("开始执行【根据id删除类别】的数据访问，参数：{}",id);
        return mapper.updateById(id);
    }


    @Override
    public int delete(Long id) {
        log.debug("开始执行【根据id删除类别】的数据访问，参数：{}"+id);
        int i = mapper.deleteById(id);
        return i;
    }
}
